$(function(){
	var params = $("#tabContent > .tab-pane.active").data();
	paramTabPage[tabId] = params;
	
	var thead='<table id="caseListTable-sub" class="table display nowrap" style="width:100%;">';
	thead+='</table>';
	$("#"+tabId+" #content").html(thead);
	var requestUrl='';
	if(paramTabPage[tabId].queryType=='diag'){
		requestUrl=contextPath+"/CaseAnalysis/notInDiagCaseData.dhc";
	}
	else if(paramTabPage[tabId].queryType=='dep'){
		requestUrl=contextPath+"/CaseAnalysis/notInDepCaseData.dhc";
	}
	else if(paramTabPage[tabId].queryType=='reason'){
		requestUrl=contextPath+"/CaseAnalysis/notInReasonCaseData.dhc";
	}
	else if(paramTabPage[tabId].queryType=='all'){
		requestUrl=contextPath+"/CaseAnalysis/notInDepCaseData.dhc";//复用未入组科室病例查询方法查询全部未入组病例，不传入depcode时即可查询全部
	}
	$.post(requestUrl,paramTabPage[tabId]).done(function(result){
		var colunms=[
	                 {
	              	   "data": "MRNO","title":'病案号',
	              	   "render": function(obj, type, full){
								var mrNo = full.MRNO;
							return "<a href=\"javascript:medicalRecord('"+full.ID+"','"+full.PATIENTNAME+"')\">"+mrNo+"</a>";
						}
	                 },
	                 { "data": "IP_COUNT",title:"住院次数" },
	                 { "data": "PATIENTNAME","title":'姓名' },
	                 {
	              	   "data": "SEX","title":'性别',
	              	   "render": function(obj, type, full) {
				               var sex=full.SEX;
				               if(sex == "1"){
				              	 sex = "男";
				               }else if(sex == "2"){
				              	 sex = "女";
				               }else{
				              	 sex = "未知";
				               }
				               return sex;
				           }
	                 },
	                 { "data": "AGEYEAR","title":'年龄' },
	                 { "data": "INDATE","title":'入院时间'},
	                 { "data": "OUTDATE","title":'出院时间'},
	                 { "data": "OUTDEP" ,"title":'出院科室'},
	                 { "data": "INDAYS","title":'住院日' },
	                 { 
	              	   "data": "COSTAMOUNT","title":'总费用(元)', "type":"numeric-comma",
	              	   "render": function(obj, type, full){
	              		   var costamount=dealwithFloat(full.COSTAMOUNT);
	              		   return costamount;
	              	   } 
	              	  
	                 },
	                 { 
	              	   "data": "DRUGCOST","title":'药品费用(元)', "type":"numeric-comma",
	              	   "render": function(obj, type, full){
	              		   var drugcost=dealwithFloat(full.DRUGCOST);
	              		   return drugcost;
	              	   } 
	                 },
	                 { "data": "NOTIN_REASON","title":'未入组原因',"render": function(obj, type, full) {
		            	 return linefeedText(getDicDesc('NOTIN_REASON',obj)=='未定义'?'未知':getDicDesc('NOTIN_REASON',obj));
		             } },
	                 { "data": "DIAGNOSECODE","title":'主要诊断ICD' },
	                 { "data": "DIAGNOSEDESSMAIN","title":'主要诊断',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
		          
	                 { "data": "BJ_ICD_CODE","title":'主要诊断ICD(对照)' },
	                 { "data": "BJ_ICD_DESC","title":'主要诊断(对照)',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
		             { "data": "OTH_DIAGINFO_CODE","title":'其他诊断ICD',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
		             { "data": "OTH_DIAGINFO_DESC","title":'其他诊断',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
		             { "data": "RES_DIA_CODE","title":'其他诊断ICD(对照)',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
		             { "data": "RES_DIA_DESC","title":'其他诊断(对照)',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
		             { "data": "OPERINFO_CODE","title":'手术操作ICD',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
	                 { "data": "OPERINFO_DESC","title":'手术操作',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
		             { "data": "RES_OPER_CODE","title":'手术操作ICD(对照)',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } },
	                 { "data": "RES_OPER_DESC","title":'手术操作(对照)',"render": function(obj, type, full) {
		            	 return linefeedText(obj);
		             } }
	                 ];
		var paramsDataTables={pageLength:50,scrollX:true,scrollY:'350px',tableTitle:'未入组病例明细表',lengthMenu:[[ 50,100,500, 1000,99999],[ 50,100,500, 1000,'全部']],columnDefs:[{"orderable": true,"targets": [0,4,5,6,7,8,10,11,12,13] },{"orderable": false,"targets": '_all'}]};
		var oTable=$("#"+tabId+" #caseListTable-sub").dataTableBasic(colunms,result.data,paramsDataTables);
		$('#'+tabId+' #caseListTable-sub_wrapper .dataTables_scrollBody table tbody').attr('id','table');//tbody加上ID，病案号的样式
		$('#'+tabId+' #caseListTable-sub_wrapper .dataTables_scrollHeadInner table thead th').css({'text-align':'center'});
		
		oTable.columns.adjust();//tbody加了样式，重新调整宽度
		
	});
	
});

function dealwithFloat(number){
	if (number!=null&& "" != number) {
		return formatNumber(Number(number).toFixed(2));
	}
	return "";
}
